<template>
  <el-dialog v-model="visible" :title="!dataForm.id ? '新增' : '修改' " :close-on-click-modal='false'
             :close-on-press-escape='false' :fullscreen='true'>
    <el-form :model="dataForm" :rules="dataRule" ref="dataFormRef" @keyup.enter.native="dataFormSubmitHandle()"
             label-width="120px">
             
                <el-form-item label="盘点号" prop="checkkey">
            <el-input v-model="dataForm.checkkey" placeholder="盘点号"></el-input>
          </el-form-item>
          <el-form-item label="行号" prop="line">
            <el-input v-model="dataForm.line" placeholder="行号"></el-input>
          </el-form-item>
          <el-form-item label="状态" prop="status">
            <el-input v-model="dataForm.status" placeholder="状态"></el-input>
          </el-form-item>
          <el-form-item label="自物料" prop="sku">
            <el-input v-model="dataForm.sku" placeholder="自物料"></el-input>
          </el-form-item>
          <el-form-item label="批号" prop="lot">
            <el-input v-model="dataForm.lot" placeholder="批号"></el-input>
          </el-form-item>
          <el-form-item label="库位编码" prop="location">
            <el-input v-model="dataForm.location" placeholder="库位编码"></el-input>
          </el-form-item>
          <el-form-item label="目的箱" prop="tray">
            <el-input v-model="dataForm.tray" placeholder="目的箱"></el-input>
          </el-form-item>
          <el-form-item label="目的格" prop="box">
            <el-input v-model="dataForm.box" placeholder="目的格"></el-input>
          </el-form-item>
          <el-form-item label="数量" prop="qty">
            <el-input v-model="dataForm.qty" placeholder="数量"></el-input>
          </el-form-item>
          <el-form-item label="初盘数量" prop="firstqty">
            <el-input v-model="dataForm.firstqty" placeholder="初盘数量"></el-input>
          </el-form-item>
          <el-form-item label="初盘人" prop="firstuser">
            <el-input v-model="dataForm.firstuser" placeholder="初盘人"></el-input>
          </el-form-item>
          <el-form-item label="初盘时间" prop="firsttime">
            <el-input v-model="dataForm.firsttime" placeholder="初盘时间"></el-input>
          </el-form-item>
          <el-form-item label="复盘数量" prop="secondqty">
            <el-input v-model="dataForm.secondqty" placeholder="复盘数量"></el-input>
          </el-form-item>
          <el-form-item label="复盘人" prop="seconduser">
            <el-input v-model="dataForm.seconduser" placeholder="复盘人"></el-input>
          </el-form-item>
          <el-form-item label="复盘时间" prop="secondaddtime">
            <el-input v-model="dataForm.secondaddtime" placeholder="复盘时间"></el-input>
          </el-form-item>
          <el-form-item label="生产日期" prop="lot1">
            <el-input v-model="dataForm.lot1" placeholder="生产日期"></el-input>
          </el-form-item>
          <el-form-item label="有效日期" prop="lot2">
            <el-input v-model="dataForm.lot2" placeholder="有效日期"></el-input>
          </el-form-item>
          <el-form-item label="是否加长" prop="lot3">
          	<el-input v-model="dataForm.lot3" placeholder="是否加长"></el-input>
          </el-form-item>
          <el-form-item label="价格" prop="lot4">
          	<el-input v-model="dataForm.lot4" placeholder="价格"></el-input>
          </el-form-item>
          <el-form-item label="部门/供应商" prop="lot5">
          	<el-input v-model="dataForm.lot5" placeholder="部门/供应商"></el-input>
          </el-form-item>
          <el-form-item label="计划单号/工序号" prop="lot6">
          	<el-input v-model="dataForm.lot6" placeholder="计划单号/工序号"></el-input>
          </el-form-item>
          <el-form-item label="主制车间" prop="lot7">
          	<el-input v-model="dataForm.lot7" placeholder="主制车间"></el-input>
          </el-form-item>
          <el-form-item label="任务编码" prop="lot8">
          	<el-input v-model="dataForm.lot8" placeholder="任务编码"></el-input>
          </el-form-item>
          <el-form-item label="新旧" prop="lot9">
          	<el-input v-model="dataForm.lot9" placeholder="新旧"></el-input>
          </el-form-item>
          <el-form-item label="作废" prop="lot10">
          	<el-input v-model="dataForm.lot10" placeholder="作废"></el-input>
          </el-form-item>
          <el-form-item label="炉批号" prop="lot11">
          	<el-input v-model="dataForm.lot11" placeholder="炉批号"></el-input>
          </el-form-item>
          <el-form-item label="材料复验号" prop="lot12">
          	<el-input v-model="dataForm.lot12" placeholder="材料复验号"></el-input>
          </el-form-item>
          <el-form-item label="牌号" prop="lot13">
          	<el-input v-model="dataForm.lot13" placeholder="牌号"></el-input>
          </el-form-item>
		  <el-form-item label="属性14" prop="lot14">
		    <el-input v-model="dataForm.lot14" placeholder="属性14"></el-input>
		  </el-form-item>
		  <el-form-item label="属性15" prop="lot15">
		    <el-input v-model="dataForm.lot15" placeholder="属性15"></el-input>
		  </el-form-item>
          <el-form-item label="备注" prop="remark">
            <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
          </el-form-item>
          <el-form-item label="回传状态" prop="backstatus">
            <el-input v-model="dataForm.backstatus" placeholder="回传状态"></el-input>
          </el-form-item>
          <el-form-item label="回传时间" prop="backdate">
            <el-input v-model="dataForm.backdate" placeholder="回传时间"></el-input>
          </el-form-item>
          <el-form-item label="回传结果" prop="backresult">
            <el-input v-model="dataForm.backresult" placeholder="回传结果"></el-input>
          </el-form-item>
          <el-form-item label="回传码" prop="backcode">
            <el-input v-model="dataForm.backcode" placeholder="回传码"></el-input>
          </el-form-item>
          <el-form-item label="仓库" prop="warehouse">
            <el-input v-model="dataForm.warehouse" placeholder="仓库"></el-input>
          </el-form-item>
          <el-form-item label="创建人" prop="adduser">
            <el-input v-model="dataForm.adduser" placeholder="创建人"></el-input>
          </el-form-item>
          <el-form-item label="创建时间" prop="addtime">
            <el-input v-model="dataForm.addtime" placeholder="创建时间"></el-input>
          </el-form-item>
          <el-form-item label="修改人" prop="updatuser">
            <el-input v-model="dataForm.updatuser" placeholder="修改人"></el-input>
          </el-form-item>
          <el-form-item label="修改时间" prop="updatetime">
            <el-input v-model="dataForm.updatetime" placeholder="修改时间"></el-input>
          </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmitHandle()">确定</el-button>
    </template>
  </el-dialog>
</template>

<script>
import {ref, reactive, onMounted, nextTick, computed} from 'vue';
import {getCheckdetailById,putCheckdetail,postCheckdetail} from "@/network/lswms/check/Checkdetail"
import {ElMessage} from 'element-plus'
import _ from 'lodash'


export default {
  name: "checkdetailAddOrUpdate",
  emits: ["refreshDataList"],
  setup(props, {emit}) {
    const visible = ref(false);
    const dataForm = ref({
		          id: '',
          checkkey: '',
          line: '',
          status: '',
          sku: '',
          lot: '',
          location: '',
          tray: '',
          box: '',
          qty: '',
          firstqty: '',
          firstuser: '',
          firsttime: '',
          secondqty: '',
          seconduser: '',
          secondaddtime: '',
          lot1: '',
          lot2: '',
          lot3: '',
          lot4: '',
          lot5: '',
          lot6: '',
          lot7: '',
          lot8: '',
          lot9: '',
          lot10: '',
		  lot11: '',
		  lot12: '',
		  lot13: '',
		  lot14: '',
		  lot15: '',
          remark: '',
          backstatus: '',
          backdate: '',
          backresult: '',
          backcode: '',
          warehouse: '',
          adduser: '',
          addtime: '',
          updatuser: '',
          updatetime: ''
    });


    const dataRule = reactive({   
                checkkey: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          line: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          status: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          sku: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          lot: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          location: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          tray: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          box: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          qty: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          firstqty: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          firstuser: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          firsttime: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          secondqty: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          seconduser: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          secondaddtime: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          lot1: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          lot2: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          lot3: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          lot4: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          lot5: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          lot6: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          lot7: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          lot8: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          lot9: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          lot10: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],        lot11: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],      lot12: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],      lot13: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],      lot14: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],      lot15: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],        remark: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          backstatus: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          backdate: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          backresult: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          backcode: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          warehouse: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          adduser: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          addtime: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          updatuser: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ],          updatetime: [
            { required: true, message: '必填项不能为空', trigger: 'blur' }
          ]    })

    const dataFormRef = ref(null)

    const init = () => {
      visible.value = true;
      nextTick(function () {
        dataFormRef.value.resetFields();
        if (dataForm.value.id) {
		getcheckdetailInfo();
		}
        
      })
    }

	const getcheckdetailInfo =()=>{
		getCheckdetailById(dataForm.value.id).then(function (res) {
		  if (res.code !== 0) {
		    return ElMessage.error(res.msg);
		  }
		  dataForm.value = _.assignIn({}, dataForm.value, res.data);
		}).catch((err) =>{
		});
	}

    // 表单提交
    const dataFormSubmitHandle = _.debounce(() => {
      dataFormRef.value.validate(function (valid) {
        if (!valid) {
          return false;
        }
		
        let qing = ()=> {
          return !dataForm.value.id ?  postCheckdetail(dataForm.value) : putCheckdetail(dataForm.value)
        }
        qing().then(function (res) {
          if (res.code !== 0) {
            return ElMessage.error(res.msg);
          }
          ElMessage({
            message: '操作成功',
            type: 'success',
            duration: 500,
            onClose: function () {
              visible.value = false
              emit('refreshDataList')
            }
          })
        }).catch(function () {
        });

      })
    }, 1000, {'leading': true, 'trailing': false})

    return {
      visible,
      dataForm,
      dataRule,
      init,
      dataFormSubmitHandle,
      dataFormRef

    }
  },


}
</script>

<style scoped>

</style>